package com.rd.student.ruanjian.class1.duhang.day0731;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;

public class Test {
    public static void main(String[] args) {
        int[] arr = new int[50];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = i;
        }
        //1
        int[] Arr = new int[arr.length];

        for (int i = 0; i < 20; i++) {
            int index = (int)(Math.random() * arr.length);

            boolean flag = false;
            for (int i1 = 0; i1 < i; i1++) {
                if (index == Arr[i1]){
                    flag = true;
                    break;
                }
            }if (flag){
                i--;
                continue;
            }
            System.out.println(arr[index]);
        }
        System.out.println("-------------------");
        //2
        int[] arr1 = new int[arr.length];

        for (int i = 0; i < arr.length; i++) {
            arr1[i] = -1;
        }

        for (int i = 0; i < 20; i++) {
            int random = (int)(Math.random() * arr.length);
            if (arr1[random] == -1){
                arr1[random] = random;
                System.out.println(arr1[random]);
            }else {
                i--;
            }
        }

        System.out.println("-----------------------------");
        //3
        ArrayList<Integer> list = new ArrayList<>(20);
        for (int i = 0; i < 20; i++) {
            int random = (int)(Math.random() * arr.length);

            if (list.contains(random)){
                i--;
                continue;
            }
            else {
                list.add(random);
                System.out.println(arr[random]);
            }
        }
        System.out.println("--------------------");
        //4
        HashSet<Integer> set = new HashSet<>();
        if (set.size() < 20){
            int random = (int)(Math.random() * arr.length);
            set.add(arr[random]);
        }
        System.out.println(set);

        System.out.println("-----------------------");

        //5

        ArrayList<Integer> list1 = new ArrayList<>(arr.length);
        for (int i = 0; i < arr.length; i++) {
            list.add(arr[i]);
        }

        Collections.shuffle(list);

        for (int i = 0; i < 20; i++) {
            System.out.println(list.get(i));
        }
    }
}
